<% if current_user then %>
<%= form_for(@lecture_rating) do |f| %>
  <% if @lecture_rating.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@lecture_rating.errors.count, "error") %> prohibited this lecture_rating from being saved:</h2>

      <ul>
      <% @lecture_rating.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  


  <p> Please enter your rating for the lecture <b> <%= Lecture.find(params[:lecture_id]).title %>. </b> Hover above the starts to select your rating.</p>

  <div class="hiddenField" class="field">
    <%= f.label :id %><br />
    <%= f.text_field :id %>
  </div>
  <div class="hiddenField" class="field">
    <%= f.label :lecture_id %><br />
    <%= f.number_field :lecture_id , :value => params[:lecture_id]  %>
  </div>
  <div class="hiddenField" class="field">
    <%= f.label :user_id %><br />
    <%= f.number_field :user_id, :value => current_user.id %>
  </div>

  <p>
  <% (0..4).each do |i| %>
      <% if i == 0 then %>
          <%= image_tag("star.png", :alt => "star", :width => "30", :class => "starRating", :id => i.to_s) %>
      <% else %>
          <%= image_tag("starEmpty.png", :alt => "starEmpty", :width => "30", :class => "starRating", :id => i.to_s) %>
      <% end %>
  <% end %>
  </p>

  <div class="hiddenField">
    <%= f.label :rating, "Rating: (1-5)" %><br />
    <%= f.number_field :rating %>
  </div>
  <div class="field">
    Difficulty:
    <select id="lecture_rating_difficulty" name="lecture_rating[difficulty]">
      <option value="" selected="selected">Please lecture difficulty</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select>
  </div>
    <div class="field">
      Work Load:
      <select id="lecture_rating_work_load" name="lecture_rating[work_load]" type="number">
        <option value="" selected="selected">Select lecture work load</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
      </select>
    </div>
  <div class="field">
    <%= f.label :comment %><br />
    <%= f.text_field :comment %>
  </div>
  <div class="actions">
    <%= f.submit "Save my rating", :class => "shinyButton" %>
  </div>
<% end %>


<% else %>
<p> Please log in to rate the lecture</p>
<% end %>



<script>
    var $jQuery = jQuery.noConflict();
    $jQuery(".starRating").mouseenter(function() {
        //alert("On Star with ID: " + this.id);
        var rating = 1;
        var srcFull = "../../assets/star.png";
        var srcEmpty = "../../assets/starEmpty.png";
        for (var i = 0; i < 5; i++){
            var currentElement = ".starRating#" + i;
            if (i <= this.id){
                $jQuery(currentElement).attr("src",srcFull);
            }
            else{
                $jQuery(currentElement).attr("src",srcEmpty);
            }
            $jQuery("#lecture_rating_rating").val(parseInt(this.id)+1);
        }
    });
</script>